#pragma once

#include "head.h"
#include "thread_poll.h"
#include "read_task.h"
#include "socket.h"
#include "tcp_connect.h"

using std::cout;
using std::endl;

class NetServer: public NoCopyable{
    using TcpConnectP = shared_ptr<TcpConnect>;
private:
    string ip_;
    short port_;
    ThreadPoll *threadPoll_;
    int sfd_;
    int epfd_;
    int sigfd_;
    unordered_map<int, TcpConnectP> tcpMp_;

private:
    // 初始化网络
    int init_();
    int initSig_();
    // 添加监听的描述符
    void addEpfd(int fd);
    void delEpfd(int fd);

    void acceptNewfd();
    void handleRequest(int fd);

    bool isClose(int fd);
    void close(int fd);

public:
    void start();

public:
    NetServer(const string &ip, short port);
    ~NetServer();
};